<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">小组信息查看</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>学员小组信息查看</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar" id="groupInfo" style="font-size: 20px;text-align: center;">
            <div>
                <span>小组名称：</span><span id="groupName" style="color: #9F9F9F"></span>
                <span>------班主任：</span><span id="headName" style="color: #9F9F9F"></span>
            </div>
        </div>
        <div class="layui-form toolbar">
            <input id="member-search-value" class="layui-input search-input" type="text" placeholder="输入成员名称"/>&emsp;
            <button id="member-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
        </div>

        <table class="layui-table" id="group-table" lay-filter="group-table"></table>
    </div>
</div>



<script>
    layui.use(['form', 'index','table', 'util', 'config', 'admin', 'layer'], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var layer = layui.layer;
        var util = layui.util;
        var admin = layui.admin;
        var index = layui.index;
        var layer = layui.layer;

        var login_user;
        var group;

        // 获取当前用户信息
        index.getUser(function (user) {
            login_user = user;
            console.log(login_user)
        });

        admin.req("api-user/group/getGroupByMember",{
            userid:login_user.id
        },function (data){
            console.log(data)
            group = data.data;
            if (data.data == null){
                $("#groupInfo").html("你还未加入任何小组！！！")
                return
            }
            $("#groupName").html(data.data.gpname);
            $("#headName").html(data.data.teaname);
        },"GET")

        // 渲染表格
        table.render({
            elem: '#group-table',
            // url: config.base_server + 'user_query.json',
            url: config.base_server + 'api-user/group/selectUserByGroup'+'?access_token='+config.getToken().access_token+'&grouid='+group.grouid,
            method: 'post',
            where: {
                // access_token: config.getToken().access_token
            },
            page: true,
            cols: [[
                {type: 'numbers'},
                {field: 'username', sort: true, title: '用户名'},
                {field: 'nickname', sort: true, title: '昵称'},
                {field: 'phone', sort: true, title: '联系电话'},
                {field: 'email', sort: true, title: '邮箱'},
                {
                    sort: true, templet: function (d) {
                        return d.sex==0?'男':'女';
                    }, title: '性别'
                },
                {
                    sort: true, templet: function (d) {
                        return util.toDateString(d.updtim);
                    }, title: '修改时间'
                }
            ]]
        });



        // 搜索按钮点击事件
        $('#member-btn-search').click(function () {
            var value = $('#member-search-value').val();
            table.reload('group-table', {where: {searchKey: value}});
        });


    });
</script>